import { Module } from '@nestjs/common';
import { ThrottlerModule } from '@nestjs/throttler';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { AuthModule } from './modules/auth/auth.module';
import { SequelizeModule } from '@nestjs/sequelize';
import { ConfigModule, ConfigService } from '@nestjs/config';
import App_globalConfig from './config/configuration'; // 全局配置
import DatabaseConfig, { OldDatabaseConfig } from './config/database'; // 数据库配置
import { ResumeModule } from './modules/resume_list/resume_list.module';
import { TemplateModule } from './modules/template_list/template_list.module';
import { SyncModule } from './modules/sync_data/index.module';
import { UploadModule } from './modules/upload/upload.module';
import { EssayModule } from './modules/essay/index.module';
import { PaymentModule } from './modules/payment/index.module';
import { StationModule } from './modules/station/index.module';
@Module({
  imports: [
    ConfigModule.forRoot({
      envFilePath: `.${process.env.NODE_ENV}.env`, // 设置 .env 文件路径
      isGlobal: true,
      load: [App_globalConfig, DatabaseConfig, OldDatabaseConfig],
    }),
    SequelizeModule.forRootAsync({
      imports: [ConfigModule],
      useFactory: async (configService: ConfigService) => {
        return configService.get('database');
      },
      inject: [ConfigService],
    }),
    SequelizeModule.forRootAsync({
      name: 'resume', // 设置数据库连接的名称
      imports: [ConfigModule],
      useFactory: async (configService: ConfigService) => {
        return configService.get('old_database');
      },
      inject: [ConfigService],
    }),
    AuthModule,
    ResumeModule,
    TemplateModule,
    SyncModule,
    UploadModule,
    EssayModule,
    PaymentModule,
    StationModule,
    StationModule,
    ThrottlerModule.forRoot([
      {
        ttl: 12000,
        limit: 3,
      },
    ]),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
